<template>
  <div class="content_box">
    <div class="list_box" v-if="list.length">
      <div @click="clickCz(item)" class="list" v-for="(item,index) in list" :key="index">
        <p>{{item.thaliName}}</p>
        <van-icon color="#999" name="arrow" />
      </div>
  
    </div>
    <div class="no_data" v-else>
      <img src="/static/images/no_sp.png" alt="">
      <p class="text">暂无套餐</p>
    </div>
    <!-- 弹窗 -->
    <div class="pop_box">
      <van-popup position="bottom" :show="isAdmin" @close="closePop">
        <div class="box">
          <div class="title">
            <p>套餐操作</p>
          </div>
          <div class="list">
            <p class="name">编辑套餐</p>
            <p class="icon" @click="toEdit(true)">
              编辑
            </p>
          </div>
          <div class="list" @click="del">
            <p class="name">删除套餐</p>
            <p class="icon">
              删除
            </p>
          </div>
          <p class="line"></p>
          <p class="quxiao" @click="isAdmin = false">取消</p>
        </div>
      </van-popup>
    </div>
    <div class="anniu_box" :style="{paddingBottom:isIphoneXnum+'px'}">
      <div class="box" :style="{paddingBottom:isIphoneXnum+'px'}">
        <p class="anniu" @click="toEdit(false)"><van-icon name="plus" /> 新增套餐</p>
      </div>
    </div>
  </div>
</template>
 
<script>
import {
  getRoomThaliList,
  delRoomThali 
} from "@/api/index";
export default {
  components: {},
  data() {
    return {
      list:[],
      id:'',
      isAdmin:false,
      isIphoneXnum:false,
      roomId:''
    };
  },
  onShow() {
    this.getList()
  },

  methods: {

    // 关闭弹窗
    closePop(){
      this.isAdmin = false
    },

    // 操作弹窗
    clickCz(item){
      this.isAdmin = true
      this.id = item.id
    },
    toEdit(state){
      this.isAdmin = false
      if(state){
        wx.navigateTo({
          url: `/pages/home/roomAdmin/editTc/edit/main?id=${this.id}&roomId=${this.roomId}`,
        });
        return
      }
      wx.navigateTo({
          url: `/pages/home/roomAdmin/editTc/edit/main?roomId=${this.roomId}`,
        });
    },

    // 套餐列表
    getList(){
      this.$showLoading('加载中...')
      getRoomThaliList({roomId:this.roomId}).then(res=>{
        if(res.statusCode == '00000'){
          this.list = res.data
          wx.hideLoading()
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }else{
          wx.hideLoading()
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }
      })
    },

    // 删除优惠券
    del(){
      wx.showModal({
        title: "温馨提示",
        content: "确定删除该条数据~",
        confirmText:'确认删除',
        success: (res)=>{
          if (res.confirm) {
            delRoomThali({id:this.id}).then(res=>{
              if(res.statusCode == '00000'){
                this.isAdmin = false
                this.getList()
              }else{
                this.$toast(res.message)
              }
            })
          }
        },
      });
    },
  },
  onLoad(options) {
    this.roomId = options.roomId
    //判断手机机型，动态给底部添加样式
    wx.getSystemInfo({
      success: (res) => {
        console.log("手机信息res" + res.model);
        let modelmes = res.model;
        if (
          modelmes.search("iPhone 13") != -1 ||
          modelmes.search("iPhone 12") != -1 ||
          modelmes.search("iPhone 11") != -1 ||
          modelmes.search("iPhone X") != -1 ||
          modelmes.search("iPhone XR") != -1 ||
          modelmes.search("iPhone XS") != -1
        ) {
          this.isIphoneXnum = 25;
        } else {
          this.isIphoneXnum = 0;
        }
      },
    });
  },
  // 下拉刷新
  onPullDownRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading();
    this.getList()
  },
  onHide() {},

  onUnload() {},
};
</script>

<style lang="scss" scoped>
.list_box{
  margin:0 30rpx;
  .list{
    height: 100rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom:1px solid #f5f5f5;
    font-size:30rpx;
    p{
      display: flex;
      align-items: center;
      span{
        display: flex;
        height: 28rpx;
        line-height: 28rpx;
        background: #1E68FF;
        border-radius: 8rpx;
        text-align: center;
        color:#fff;
        font-size:20rpx;
        margin-left:10rpx;
        align-items: center;
        justify-content: center;
        padding:0 10rpx;
      }
    }
  }
}
.anniu_box{
  height: 150rpx;
  width: 100%;
  background: #fff;
  position: fixed;
  bottom:0;
  left: 0;
  .box{
    width: 92%;
    height: 150rpx;
    line-height: 150rpx;
    padding:0 30rpx;
    background: #fff;
    display: flex;
    align-items: center;
    .anniu{
      box-shadow: 0rpx 10rpx 20rpx #CEDBFA;
      border:none;
      width: 100%;
      height: 88rpx;
      line-height: 88rpx;
      background: #1E68FF;
      border-radius: 100rpx;
      text-align: center;
      color: #fff;
      font-size: 30rpx;
    }
  }
}
.no_data{
  text-align: center;
  font-size:28rpx;
  color:#333;
  padding-top:150rpx;
  .text{
    font-weight: 500;
    color:#999;
  }
  img{
    width: 248rpx;
    height: 248rpx;
  }
}
.pop_box{
  /deep/ .van-popup {
    border-top-right-radius: 20rpx !important;
    border-top-left-radius: 20rpx !important;
  }
  .box{
    .title{
      height: 104rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      color:#323233;
      font-size:34rpx;
      border-bottom:1px solid #f0f0f0;
      position: relative;
      .tb{
        position: absolute;
        right:30rpx;
      }
    }
    .list{
      height: 104rpx;
      border-bottom:1px solid #f5f5f5;
      padding:0 40rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .name{
        font-size:32rpx;
        color:#323233;
      }
      .icon{
        width: 196rpx;
        height: 60rpx;
        display:flex;
        align-items: center;
        justify-content: center;
        border:1px solid #222;
        color:#222;
        font-size:28rpx;
        font-weight: 500;
        border-radius: 50rpx;
        &.on{
          opacity: 0.5;
        }
      }
      div{
        display: flex;
      }
      .tips{
        font-size:24rpx;
        color:red;
        margin-top:10rpx;
      }
      img{
        width: 32rpx;
        height: 32rpx;
        margin-right:10rpx;
      }
    }
    .line{
      width: 100%;
      height: 16rpx;
      background: #f8f8f8;
    }
    .quxiao{
      height: 100rpx;
      line-height: 100rpx;
      font-size:32rpx;
      color:#323233;
      text-align: center;
    }
  }
}
</style>
